package com.itheima.config;

import com.itheima.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//SpringMVC配置类：配置拦截器，视图解析器，消息转换器等
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor TokenInterceptor;

//    @Autowired
//    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(myInterceptor)//注册拦截器
//                .addPathPatterns("/**");//配置拦截器的拦截路径， /** 表示所有路径

        registry.addInterceptor(TokenInterceptor)//注册拦截器
                .addPathPatterns("/**")//配置拦截器的拦截路径， /** 表示所有路径
                .excludePathPatterns("/login");//配置不拦截的路径
    }
}
